/**
 * 基础菜单 商品管理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>后勤保障</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="请假人：">
        <el-input size="small" v-model="formInline.varName" placeholder="请输入请假人姓名"></el-input>
      </el-form-item>
      <el-form-item >
        <el-button type="primary" size="middle">搜索</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="selection" width="60">
      </el-table-column>
      <el-table-column  prop="nick" label="请假人员" width="100">
      </el-table-column>
      <el-table-column  prop="des" label="请假原因" width="200">
      </el-table-column>
      <el-table-column  prop="start" label="开始时间" width="200">
      </el-table-column>
      <el-table-column sortable prop="end" label="结束时间" width="200">
       </el-table-column>
       <el-table-column sortable prop="total" label="总计时间" width="200">
       </el-table-column>
       <el-table-column sortable prop="remainningDays" label="剩余天数" width="200">
       </el-table-column>
      <el-table-column sortable prop="status" label="请假状态" width="100">
        <template slot-scope="scope">
          <el-tag :type="scope.row.status=='0'?'danger':'success'">{{scope.row.status==1?'已同意':(scope.row.status==0?'已驳回':"申请中")}}</el-tag>
         </template>
      </el-table-column>
      
      <el-table-column align="center" label="操作" min-width="300">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(1, scope.row)"  :disabled="scope.row.status==1">批准</el-button>
          <el-button size="mini" type="danger" @click="handleEdit(0, scope.row)"
          :disabled="scope.row.status==0">驳回</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    <!-- 编辑界面 -->
  </div>
</template>

<script>
import { deptList, deptSave, deptDelete } from '../../api/userMG'
import Pagination from '../../components/Pagination'
import {getLeaveList, ratifyLeave} from '@/api'

export default {
  data() {
    return {
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '添加',
      editForm: {
        deptId: '',
        deptName: '',
        deptNo: '',
        token: localStorage.getItem('logintoken')
      },
      formInline: {
        current: 1,
        size: 10,
        total: 10,
        nick:''

       
      },
      
      userparm: [], //搜索权限
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getdata(this.formInline)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取列表
    getdata(parameter) {
      this.loading = true
      getLeaveList(parameter).then(res=>{
        console.log(res)
        this.listData = res.result.records
      this.formInline.current = res.result.current
      this.formInline.size = res.result.size
      this.formInline.total = res.result.total;
      this.loading = false;
      })
      // 模拟数据开始
      // let res = {
      //   code: 0,
      //   msg: null,
      //   count: 10,
      //   data: [
      //     {
      //       logisticsName: '小李',
      //       logisticsCause: '家里有事',
      //       start: '2023-03-12 9:00',
      //       end: '2023-03-12 18:00',
      //       logisticsTime: '8小时',
      //       total: '2天',
      //       logisticsId: '46546854674854',
      //       status:'未批准'
      //     },
      //   ]
      // }
      // this.loading = false
      // this.listData = res.data
      // this.pageparm.currentPage = this.formInline.page
      // this.pageparm.pageSize = this.formInline.limit
      // this.pageparm.total = res.count
      // 模拟数据结束

      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */
      // deptList(parameter)
      //   .then(res => {
      //     this.loading = false
      //     if (res.success == false) {
      //       this.$message({
      //         type: 'info',
      //         message: res.msg
      //       })
      //     } else {
      //       this.listData = res.data
      //       // 分页赋值
      //       this.pageparm.currentPage = this.formInline.page
      //       this.pageparm.pageSize = this.formInline.limit
      //       this.pageparm.total = res.count
      //     }
      //   })
      //   .catch(err => {
      //     this.loading = false
      //     this.$message.error('菜单加载失败，请稍后再试！')
      //   })
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },
    //显示编辑界面
    handleEdit: function(index, row) {
      let data = {
        id:row.id,
        result:index
      }
      ratifyLeave(data).then(res=>{
        console.log(res)
        if(res.code==200){
          this.$message.success('操作成功')
          this.getdata(this.formInline)
        }else{
          this.$message.error('操作失败')
        }
      })
    },
    // 编辑、增加页面保存方法
    submitForm(editData) {
      this.$refs[editData].validate(valid => {
        if (valid) {
          deptSave(this.editForm)
            .then(res => {
              this.editFormVisible = false
              this.loading = false
              if (res.success) {
                this.getdata(this.formInline)
                this.$message({
                  type: 'success',
                  message: '公司保存成功！'
                })
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.editFormVisible = false
              this.loading = false
              this.$message.error('公司保存失败，请稍后再试！')
            })
        } else {
          return false
        }
      })
    },
    // 删除公司
    deleteUser(index, row) {
      this.$confirm('确定要删除该产品信息吗?', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deptDelete(row.deptId)
            .then(res => {
              if (res.success) {
                this.$message({
                  type: 'success',
                  message: '产品已删除!'
                })
                this.getdata(this.formInline)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error('产品删除失败，请稍后再试！')
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 关闭编辑、增加弹出框
    closeDialog() {
      this.editFormVisible = false
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

 
 